package com.example.administrator.produceqr;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2018/1/24 0024.
 */

public class PhoneAdapter extends RecyclerView.Adapter<PhoneAdapter.PhoneHolder>{
    private Context mContext;
    private LayoutInflater inflater;
    private List<ContactInfo> infoList;

    public PhoneAdapter(Context context, List<ContactInfo> list){
        mContext = context;
        inflater = LayoutInflater.from(context);
        infoList = list;
    }

    @Override
    public PhoneHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.phone_item, parent, false);
        PhoneHolder holder = new PhoneHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(PhoneHolder holder, int position) {
        ContactInfo infoItem = infoList.get(position);
        if (infoItem == null)return;
        String name = infoItem.name;
        String phone = infoItem.phone;
        holder.nameText.setText(name);
        holder.phoneText.setText(phone);
    }

    @Override
    public int getItemCount() {
        return infoList.size();
    }

    class PhoneHolder extends RecyclerView.ViewHolder {
        private ImageView pictureImg;
        private TextView nameText, phoneText;

        public PhoneHolder(View itemView) {
            super(itemView);

            pictureImg = (ImageView) itemView.findViewById(R.id.pictureImg);
            nameText = (TextView) itemView.findViewById(R.id.nameText);
            phoneText = (TextView) itemView.findViewById(R.id.phoneText);
        }
    }
}
